package com.lyf.scm.admin.domain.remote.allocationservice.facade;


import com.alibaba.fastjson.JSON;
import com.github.pagehelper.PageInfo;
import com.lyf.scm.admin.api.dto.GmvTargetDTO;
import com.lyf.scm.admin.api.dto.GmvTargetInfoDTO;
import com.lyf.scm.admin.domain.remote.allocationservice.GmvTargetRemote;
import com.lyf.scm.common.enums.ResponseMsg;
import com.rome.arch.core.clientobject.Response;
import com.rome.arch.core.exception.RomeException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * description:
 * gmv指标正面
 *
 * @author: haodong
 * @data: 2020/7/8 16:36
 */
@Service
@Slf4j
public class GmvTargetFacade {

    @Resource
    private GmvTargetRemote gmvTargetRemote;

    /**
     * 按条件查询gmv指标(天)
     *
     * @param gmvTarget
     * @return
     */
    public PageInfo<GmvTargetInfoDTO> listBySelective(GmvTargetDTO gmvTarget) {
        log.info("按条件查询gmv指标(天)入参:GmvTargetDTO:{}", JSON.toJSONString(gmvTarget));
        Response<PageInfo<GmvTargetInfoDTO>> response = gmvTargetRemote.listBySelective(gmvTarget);
        if (!response.getCode().equals(ResponseMsg.SUCCESS.getCode())) {
            throw new RomeException(response.getCode(), response.getMsg());
        }
        return response.getData();
    }

    /**
     * 查询全渠道gmv指标(范围)
     *
     * @param gmvTarget
     * @return
     */
    public List<GmvTargetInfoDTO> listAllBySelective(GmvTargetDTO gmvTarget) {
        log.info("查询全渠道gmv指标(范围)入参:GmvTargetDTO:{}", JSON.toJSONString(gmvTarget));
        Response<List<GmvTargetInfoDTO>> response = gmvTargetRemote.listAllBySelective(gmvTarget);
        if (!response.getCode().equals(ResponseMsg.SUCCESS.getCode())) {
            throw new RomeException(response.getCode(), response.getMsg());
        }
        return response.getData();
    }

    /**
     * 批量新增
     *
     * @param gmvTargetList
     * @return
     */
    public Boolean batchSave(List<GmvTargetDTO> gmvTargetList) {
        log.info("销售额目标批量新增入参:GmvTargetDTO:{}", JSON.toJSONString(gmvTargetList));
        Response<Boolean> response = gmvTargetRemote.batchSave(gmvTargetList);
        if (!response.getCode().equals(ResponseMsg.SUCCESS.getCode())) {
            throw new RomeException(response.getCode(), response.getMsg());
        }
        return response.getData();
    }

    public feign.Response exportExcel(GmvTargetDTO gmvTargetDTO, Integer type) {
        log.info("销售额目标导出入参:GmvTargetDTO:{}", JSON.toJSONString(gmvTargetDTO));
        return gmvTargetRemote.exportExcel(gmvTargetDTO, type);
    }

    /**
     * 更新销售额目标
     * @param gmvTarget
     * @return
     */
    public Boolean updateTarget(List<GmvTargetDTO> gmvTarget) {
        log.info("更新销售额目标入参:GmvTargetDTO:{}", JSON.toJSONString(gmvTarget));
        Response<Boolean> response = gmvTargetRemote.updateTarget(gmvTarget);
        if (!response.getCode().equals(ResponseMsg.SUCCESS.getCode())) {
            throw new RomeException(response.getCode(), response.getMsg());
        }
        return response.getData();
    }

    public void delete(String opSign) {
        log.info("删除销售额目标:{}", JSON.toJSONString(opSign));
        gmvTargetRemote.delete(opSign);
    }
}
